package com.example.project1

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import android.graphics.Color

class MainActivity : ComponentActivity() {
    val export = Program()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        // 只保留XML布局加载
        setContentView(R.layout.mainlayout)

        val spinner = findViewById<Spinner>(R.id.spinner2)
        val button = findViewById<Button>(R.id.button1)
        val textView = findViewById<TextView>(R.id.textView)

        // 注意：按钮通常使用setOnClickListener而不是setOnKeyListener
        button.setOnClickListener {
            val selectedFeature = spinner.selectedItem?.toString() ?: ""
            textView.text = export.getLanguage(spinner.selectedItem.toString())
        }

        val dynamicTexts: LinearLayout = findViewById(R.id.dynamic_texts)
        val buttonAddText: Button = findViewById(R.id.button2)

        buttonAddText.setOnClickListener {
            val count = dynamicTexts.childCount+1
            val dynamicText= TextView(this).apply{
                text="This is a new TextView: $count\n"
                textSize=16f
                setTextColor(Color.RED)
                setBackgroundColor(Color.YELLOW)
                setPadding(16,12,16,12)
            }
            dynamicTexts.addView(dynamicText)
        }
    }
}